import AsyncStorage from '@react-native-async-storage/async-storage';
/**
 * 存储localStorage
 */
export const setStore = async (name, content) => {
  if (!name) {
    return;
  }
  try {
    if (typeof content !== 'string') {
      content = JSON.stringify(content);
    }
    await AsyncStorage.setItem(name, content);
  } catch (e) {
    // saving error
  }
};

/**
 * 获取localStorage
 */
export const getStore = async name => {
  if (!name) {
    return;
  }
  try {
    return await AsyncStorage.getItem(name);
  } catch (e) {
    // error reading value
  }
};

/**
 * 删除localStorage
 */
export const removeStore = async name => {
  if (!name) {
    return;
  }

  try {
    await AsyncStorage.removeItem(name);
  } catch (e) {
    // error reading value
  }
};
